<?php
 //session_start();
 include 'Db.php';
 include './libs/Smarty.class.php';

 //方法的定义尽量用动词+名词
 //定义太多  自己都记不住
 class UserAction{
    
	//定义数据库和模版引擎
	public $db;
	public $smarty;
    	
	//构造函数，实例化db和smarty对象
	function __construct() {
	   $this->db=new DB();
	   $this->smarty=new Smarty();
	}
	//首页，用户跳转到二维码页面
	function index(){
	    $this->smarty->display("code.html");	
/* 		$sql="select * from user ";
		$res=$this->db->query($sql);
		$info=array();
		//循环结果集  将记录存入数组
		while($row = mysql_fetch_array($res)){
             array_push($info,$row);
		} */

	}
	
	
	//用户提交中奖号码
	function get(){
	    if(isset($_POST['phone'])){
			$sql="select * from user where phone='".$_POST['phone']."'";
			$res=$this->db->query($sql);
			$info=mysql_fetch_assoc($res);
			if(empty($info)){
			    $str="对不起,请先参加我们的活动";
				$this->smarty->assign("info",$str);
				$this->smarty->display("info.html");
			}else{
			   if($info['isget']=="1"){
				    $str='您中了'.$info['level'].'等奖，奖品是'.$info['prize'];
					$this->smarty->assign("info",$str);	
                    $this->smarty->display("info.html");					
			   }else{
					$str="对不起,您的奖品已经领过啦";
					$this->smarty->assign("info",$str);
					$this->smarty->display("info.html");
			   }

			}		
		}else{
		   $this->smarty->display("code.html");
		}

	}


	//发生错误函数  给用户提示信息
	function error($info){
	    $this->smarty->assign("error",$info);
	    $this->smarty->display("error.html");	   
	}
	
	//销毁用户登录痕迹
	function out(){
	    unset($_SESSION['phone']);
	}
}

?>